package com.summer.data.parameter.clob;

import com.summer.data.parameter.ClobParameter;

import java.io.*;

/**
 * @author 345480567@qq.com
 */
public class FileClobParameter implements ClobParameter {

    private String fileName;

    private Integer len = 0;

    public FileClobParameter(String fileName) {
        this.fileName = fileName;
    }

    @Override
    public void write(Writer writer) {
        try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
            String nextLine = "";
            while ((nextLine = br.readLine()) != null) {
                writer.write(nextLine);
                len += nextLine.length();
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String toString() {
        return "FileClobParameter{}" + len;
    }
}
